package com.hxzy.controller;


import com.hxzy.message.Demo01Message;
import com.hxzy.message.MySource;
import org.apache.rocketmq.common.message.MessageConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@RequestMapping("/stream/bridge")
public class DemoNewsController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 队列名称
     */
    public final static  String DEMO01OUTPUT="demo01-output";


    @Autowired
    private StreamBridge streamBridge;

    @GetMapping("/send")
    public boolean send() {
        // 创建 Message
        Demo01Message message = new Demo01Message().setId(new Random().nextInt());
        // 创建 Spring Message 对象
        Message<Demo01Message> springMessage = MessageBuilder.withPayload(message).build();
        // 发送同步消息
        boolean send = this.streamBridge.send(DEMO01OUTPUT,springMessage);
        return send;
    }


}
